package ping.mp3player;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import ping.model.Mp3Info;
import ping.utils.FileUtils;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class LocalMp3ListActivity extends ListActivity {

	private List<Mp3Info> mp3Infos = null;
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		//System.out.println("onResume........");
		FileUtils fileUtils = new FileUtils();
		 mp3Infos = fileUtils.getMp3Files("mp3/");
		 System.out.println("Local_onResume=="+mp3Infos);
		List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		for (Iterator iterator = mp3Infos.iterator(); iterator.hasNext();) {
			Mp3Info mp3Info = (Mp3Info) iterator.next();
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("mp3_name", mp3Info.getMp3Name());
			map.put("mp3_size", mp3Info.getMp3Size());
			list.add(map);
		}
		SimpleAdapter adapter = new SimpleAdapter(this, list,
				R.layout.mp3_list_item,
				new String[] { "mp3_name", "mp3_size" }, new int[] {
						R.id.mp3_name, R.id.mp3_size });
		setListAdapter(adapter);

		super.onResume();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.local_mp3_list);

	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		Mp3Info mp3Info = mp3Infos.get(position);
		Intent intent = new Intent();
		System.out.println("Localmp3Lick---"+mp3Info);
		intent.putExtra("mp3info", mp3Info);
		intent.setClass(this, PlayerActivity.class);
		startActivity(intent);
		super.onListItemClick(l, v, position, id);
	}

}
